package org.jeecg.modules.flower.jimuapi;/**
 * @author gf
 * @create 2022-11-4 14:33
 */

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.flower.entity.*;
import org.jeecg.modules.flower.service.*;
import org.jeecg.modules.flower.util.CommonUtil;
import org.jeecg.modules.system.service.ISysDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 *
 * @ClassName OrderForJimuController
 * @description: TODO
 * @author gf
 * @datetime 2022年 11月 04日 14:33
 * @version: 1.0
 **/
@RestController
@Slf4j
@Api(tags = "积木报表API")
@RequestMapping("/flower/jimu/flowerOutorder")
public class OrderForJimuController {


    @Autowired
    private IFlowerOutorderinfoService flowerOutorderinfoService;
    @Autowired
    private IFlowerOutorderinfoDService flowerOutorderinfoDService;
    @Autowired
    private ISysDictService sysDictService;
    @Autowired
    private IFlowerOutorderPreService flowerOutorderPreService;
    @Autowired
    private IFlowerOutorderPreinfoService flowerOutorderPreinfoService;
    @Autowired
    private IFlowerStorehouseService flowerStorehouseService;


    /**
     * 导出excel  出库单--积木报表
     *
     * @param request
     * @param flowerOutorderPage
     * @return
     */
    @ApiOperation(value = "出库单子表--积木报表 ")
    @GetMapping(value = "/getOrderInfos")
    public JSONObject getOrderInfos(HttpServletRequest request, FlowerOutorder flowerOutorderPage) {
        JSONObject rest = new JSONObject();
        String id = flowerOutorderPage.getId();
        List<FlowerOutorderinfo > data   = flowerOutorderinfoService.selectByMainId(id);
        if (data.size() == 0) {
            throw new RuntimeException("没有出库详情不能生成出库单");
        }
        Map<String, String> costNames = CommonUtil.getCostNames();
        Map<String, String> houseNames = CommonUtil.getHouseNames();
        for (FlowerOutorderinfo flowerOutorderinfo : data) {
            flowerOutorderinfo.setStorehouse(houseNames.get(flowerOutorderinfo.getStorehouse()));
            flowerOutorderinfo.setCost(costNames.get(flowerOutorderinfo.getCost()));
        }
        rest.put("data",data);
        return rest;
    }

    /**
     * 导出excel  预出库单子表--积木报表
     *
     * @param request
     * @param FlowerOutorderPre
     * @return
     */
    @ApiOperation(value = "预出库单子表--积木报表 ")
    @GetMapping(value = "/getOrderPreInfos")
    public JSONObject getOrderPreInfos(HttpServletRequest request, FlowerOutorderPre FlowerOutorderPre) {
        JSONObject rest = new JSONObject();

        String id = FlowerOutorderPre.getId();
        List<FlowerOutorderPreinfo > data = flowerOutorderPreinfoService.selectByMainId(id);
        if (data.size() == 0) {
            throw new RuntimeException("没有出库详情不能生成出库单");
        }
        Map<String, String> costNames = CommonUtil.getCostNames();
        Map<String, String> houseNames = CommonUtil.getHouseNames();
        for (FlowerOutorderPreinfo flowerOutorderPreinfo : data) {
            flowerOutorderPreinfo.setStorehouse(houseNames.get(flowerOutorderPreinfo.getStorehouse()));
            flowerOutorderPreinfo.setCost(costNames.get(flowerOutorderPreinfo.getCost()));
        }
        rest.put("data",data);
        return rest;
    }


}